package com.usernet.product.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.usernet.product.comm.BaseAction;
import com.usernet.product.entity.AdminLog;
import com.usernet.product.utils.DateUtils;
import com.usernet.product.utils.Page;
import com.usernet.product.utils.PageResult;
import com.usernet.product.web.form.AdminLogForm;

public class AdminLogAction extends BaseAction {

	public ActionForward toList(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		AdminLogForm mForm = (AdminLogForm) form;
		// 查询条件
		String time = mForm.getTime();
		String loginName = mForm.getLoginName();

		PageResult<AdminLog> result = null;
		Page page = new Page();
		// 分页信息
		String pageNo = mForm.getPageNo();
		String pageSize = mForm.getPageSize();
		if (pageSize != null) {
			page.setEveryPage(Integer.parseInt(pageSize.trim()));
		}
		if (pageNo != null) {
			page.setCurrentPage(Integer.parseInt(pageNo.trim()));
		}
		// 条件查询
		if (time != null || loginName != null) {
			// 有条件
			result = adminLogDao.getAllByParam(page, loginName, DateUtils
					.stringToTimestampBegin(time), DateUtils
					.stringToTimestampEnd(time));
		} else {
			result = adminLogDao.getAllByPage(page);
		}
		request.setAttribute("form", mForm);
		request.setAttribute("list", result.getContent());
		request.setAttribute("page", result.getPage());
		request.setAttribute("size", result.getSize());

		return mapping.findForward("list");
	}

	public ActionForward toInfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		int id = Integer.parseInt(request.getParameter("id"));
		AdminLog log = (AdminLog) adminLogDao.getById(AdminLog.class, id);
		request.setAttribute("adminLog", log);
		return mapping.findForward("info");
	}

}
